package com.ldxiwxr.controller.controller;

import cn.hutool.extra.servlet.ServletUtil;
import com.ldxiwxr.common.common.Result;
import com.ldxiwxr.system.query.UserListQuery;
import com.ldxiwxr.system.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 用户控制类
 * @author SuBanxia
 */
@RestController
@Api(tags = "/UserController")
@RequestMapping("/user")
public class UserController {

    @Resource
    private IUserService userService;

    @ApiOperation("获取当前登录用户信息")
    @GetMapping("/getUserById")
    public Result<?> getUserById(){
        return Result.data(userService.getUser());
    }

    @ApiOperation("向用户发送短信")
    @PostMapping("/sendMsg")
    public Result<?> sendMsg(@RequestParam("phone") String phone, @RequestParam("type") String type) {
        userService.sendMsg(phone,type);
        return Result.success();
    }

    @ApiOperation("获取全部用户")
    @PostMapping("/getAllUser")
    public Result<?> getAllUser(@RequestBody UserListQuery userListQuery){
        return Result.data(userService.getAllUser(userListQuery.getNickName(), userListQuery.getId()));
    }

    @ApiOperation("添加用户")
    @PostMapping("/addUser")
    public Result<?> addUser(){

        return null;
    }

    @ApiOperation("获取用户ip具体位置")
    @GetMapping("/getUserIp")
    public Result<?> getUserIp(HttpServletRequest request){
        String ip = ServletUtil.getClientIP(request);
        return userService.getUserIp(ip);
    }
}
